extends Node2D

var boids: Array[Boid] = []
var quadtree: QuadTree

const BOID = preload("res://场景/鸟.tscn")

func _ready():
	var screenRect = get_viewport_rect()
	quadtree = QuadTree.new(screenRect, 10)

	# 创建100个鸟随机分布在屏幕上
	for i in range(50):
		var boid = BOID.instantiate()
		boid.position = Vector2(randi_range(0, screenRect.size.x), randi_range(0, screenRect.size.y))
		add_child(boid)
		boids.append(boid)
		quadtree.insert(boid)

func _physics_process(delta: float) -> void:
	for boid in boids:
		boid.setTarget(get_global_mouse_position())
		boid.apply(delta, quadtree)
